if(!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.machines.list.MachinesList")) {
    jsx3.lang.Class.defineClass(
            "tibco.admin.enterpriseAssets.machines.list.MachinesList", //the full name of the package to create
            jsx3.lang.Object, //  extends jsx3.lang.Object
            null, // does not implements any interfaces
            function(machinesList) {          //name the argument of this function
                machinesList.matrixList = null;
                machinesList.workspace = null;
                machinesList.multiselected = false;

                machinesList.subscribeAll = function () {
                    machinesList.workspace = tibco.admin.Main.getServer().getJSXByName("blkWorkspace21");
                    machinesList.matrixList = machinesList.workspace.getDescendantOfName("mtxMachinesList21", true, false);
                    machinesList.callgetConnectedManagementDaemons();
                    tibco.admin.PubSub.subscribe("DiscoveredInstallations.ONSETASSOCIATIONS", machinesList.callgetConnectedManagementDaemons);
                }

                machinesList.tryToDisconnectManagementDaemons = function() {
                    var cacheRecords = machinesList.matrixList.getSelectedNodes();
                    tibco.admin.util.Log.SERVICE.trace("The number of checked records is [\n" + cacheRecords.getLength() + "]");
                    if(cacheRecords.getLength() == 0) {
                        tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@lblNoMachines21"), tibco.admin.Main.getServer().getDynamicProperty("@lblSelectMachines21"));
                        return;
                    }
                    machinesList.calldisconnectManagementDaemons();
                }

                //call this method to begin the service call (eg.service.calldisconnectManagementDaemons();)
                machinesList.calldisconnectManagementDaemons = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/machines/list/rules/disconnectManagementDaemons.xml",
                            "disconnectManagementDaemons",
                            "disconnect Management Daemons");
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagementDaemonEndpointURL())
                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, machinesList.ondisconnectManagementDaemonsSuccess);
                    objService.doCall();
                };

                machinesList.ondisconnectManagementDaemonsSuccess = function(objEvent) {
                    machinesList.callgetConnectedManagementDaemons();
                };

                machinesList.callgetConnectedManagementDaemons = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/machines/list/rules/getConnectedManagementDaemonsRules.xml",
                            "getConnectedManagementDaemons",
                            "get Connected Management Daemons");
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagementDaemonEndpointURL())
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, machinesList.ongetConnectedManagementDaemonsSuccess);
                    objService.subscribe(jsx3.net.Service.ON_ERROR, machinesList.ongetConnectedManagementDaemonsError);
                    objService.subscribe(jsx3.net.Service.ON_INVALID, machinesList.ongetConnectedManagementDaemonsInvalid);
                    objService.doCall();
                };

                machinesList.ongetConnectedManagementDaemonsSuccess = function(objEvent) {
                    if(!machinesList.matrixList) {
                        machinesList.matrixList = tibco.admin.Main.getServer().getJSXByName("mtxMachinesList21");
                    }

                    machinesList.matrixList.repaint();

                    var cacheDoc = machinesList.matrixList.getXML();
                    if(!cacheDoc) {
                        tibco.admin.util.Log.SERVICE.error("Cache document for the search parameters list was not found.");
                    }
                    else {
                        var flag = false;
                        if(machinesList.selection != null) {
                            var iter = machinesList.selection.iterator();
                            while(iter.hasNext()) {
                                var name = iter.next();
                                var record = machinesList.matrixList.getXML().selectSingleNode("//record[@name='" + name + "']");
                                if(record) {
                                    record.setAttribute("jsxselected", 1);
                                    if(!machinesList.multiselected) {
                                        var arr = new Array();
                                        arr.push(record.getAttribute("jsxid"));
                                        machinesList.publishSelect(arr);
                                    }
                                    flag = true;

                                }
                            }
                            machinesList.selection = null;
                        }
                        // if no node is selected, clear the edit area
                        if(!flag || machinesList.multiselected) {
                            machinesList.workspace.getDescendantOfName("btnDisconnect21").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                            var msg = new Object();
                            msg.subject = tibco.admin.enterpriseAssets.machines.EventID.MACHINES_DESELECTED;
                            tibco.admin.PubSub.publish(msg);
                        }
                    }
                };

                machinesList.ongetConnectedManagementDaemonsError = function(objEvent) {
                    //tibco.admin.util.ServiceHelper.logErrors("xmlCacheIdmachinesList202", "MachinesList", "getConnectedManagementDaemons", objEvent);
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.SERVICE.error("The service call failed. The HTTP Status code is: " + myStatus);
                    tibco.admin.util.ServiceHelper.printInboundOutboundDocument(objEvent);

                };

                machinesList.ongetConnectedManagementDaemonsInvalid = function(objEvent) {
                    tibco.admin.util.ServiceHelper.logInvalid(objEvent, "MachinesList", "getConnectedManagementDaemons")
                    tibco.admin.util.Log.SERVICE.error("The following message node just failed validation:\n\n" + objEvent.message);
                    tibco.admin.util.ServiceHelper.printInboundOutboundDocument(objEvent);

                };

                machinesList.publishSelect = function(selectedIDs) {
                    var removeButton = machinesList.workspace.getDescendantOfName("btnDisconnect21");
                    if(selectedIDs.length == 1) {
                        var record = machinesList.matrixList.getXML().selectSingleNode("//record[@jsxid='" + selectedIDs[0] + "']");
                        if(record) {
                            if(removeButton.getEnabled() == jsx3.gui.Form.STATEDISABLED)
                                removeButton.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                            var msg = new Object();
                            msg.subject = tibco.admin.enterpriseAssets.machines.EventID.MACHINES_SELECTED;
                            msg.daemonName = record.getAttribute("name");
                            msg.description = record.getAttribute("description");
                            msg.discoveryJMXUrl = record.getAttribute("discoveryJMXUrl");
                            msg.managementJMXUrl = record.getAttribute("managementJMXUrl");
                            msg.hostName = record.getAttribute("hostName");
                            msg.tibcoHome = record.getAttribute("tibcoHome");
                            msg.osName = record.getAttribute("osName");
                            msg.boundBy = record.getAttribute("boundBy");
                            tibco.admin.PubSub.publish(msg);
                        }
                    }
                    else {
                        if(removeButton.getEnabled() == jsx3.gui.Form.STATEENABLED)
                            removeButton.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                        var msg = new Object();
                        msg.subject = tibco.admin.enterpriseAssets.machines.EventID.MACHINES_DESELECTED;
                        tibco.admin.PubSub.publish(msg);
                    }
                }

                machinesList.onRefresh = function() {
                    var selectionSize = machinesList.matrixList.getSelectedNodes().size();
                    machinesList.multiselected = false;
                    if(selectionSize > 0) {
                        machinesList.selection = new jsx3.util.List(selectionSize);
                        var nodes = machinesList.matrixList.getSelectedNodes();
                        for(var i = 0; i < nodes.size(); i++) {
                            machinesList.selection.add(nodes.getItem(i).getAttribute('name'));
                        }
                        if(selectionSize > 1) {
                            machinesList.multiselected = true;
                        }
                    }

                    machinesList.callgetConnectedManagementDaemons();
                }
            }
            );
}

